
import  {useRouter} from 'vue-router'
const router = useRouter()

const state = {
    tokenHead: 'Yurun ',
    token: localStorage.getItem('token') || '',
}

const mutations = {

    // 登录成功后保存token
    setToken(state, token) {
        state.token = token
        localStorage.setItem('token', token)
    },
    // 登出后清除token
    clearToken(state) {
        state.token = ''
        localStorage.removeItem('token')
    },
    logout(state) {
        state.token = ''
        localStorage.removeItem('token')
        router.push('/login')
    }

}   

export default {
    state,
    mutations
}